<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="example"></div>
<div>
    <button onclick="executeCode()">执行</button>
    <textarea style="width:100vw" id="jscode" cols="30" rows="10"></textarea>
</div>
<script>
    window.jscode = document.getElementById('jscode');
    window.executeCode = function () {
        eval(window.jscode.value);
    };
    let exampleDiv = document.getElementById('example');
    [
        { text: 'comfirm', value: 'confirm("消息")' },
        { text: 'alert', value: 'alert("消息")' },
        { text: 'prompt', value: 'prompt("标题","默认内容")' },
        { text: 'setLocalStory', value: 'localStorage.setItem("键","值")' },
        { text: 'getLocalStory', value: 'var value = localStorage.getItem("键");alert(value);' }
    ].forEach(ex => {
        let btn = document.createElement('button');
        exampleDiv.append(btn);
        btn.innerText = ex.text;
        btn.onclick = function () {
            window.jscode.value = ex.value;
        }
    });
</script>
</body>
</html>
